package Volume1.ch9;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

/**
 * @Auther jacob
 * @Date 2020/8/15 00:09
 */
public class SetTest {

    public static void main(String[] args) {
        Set<String> words = new HashSet<>();
        long totalTime = 0;
        String[] wordString = {"aaa", "bbb", "ccc", "aaa", "ddd"};

        for (int i = 0; i < wordString.length; i++) {
            String word = wordString[i];
            long callTime = System.currentTimeMillis();
            words.add(word);
            callTime = System.currentTimeMillis() - callTime;
            totalTime += callTime;
        }

        Iterator<String> iter = words.iterator();
        for (int i = 0; i < 20 && iter.hasNext(); i++) {
            System.out.println(iter.next());
        }

        System.out.println("...");
        System.out.println(words.size() + " distinct words. " + totalTime + "ms");
    }
}
